package com.guangzhi.weijianzhi.utils;


import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;

import com.guangzhi.weijianzhi.R;

public class PopuUtils {
	public static PopupWindow showPou(View view,View inflate,final OnClickListener listener, final Context con){
		final PopupWindow window = new PopupWindow(inflate, LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT,true );
 
		addAttriBute(window);
		changeActivity((Activity)con);
		changeActivity(window,(Activity)con);
		window.showAtLocation(view, Gravity.BOTTOM, 0, 0);
	
		return window;
	}
	
	
	public static void addAttriBute(PopupWindow window){
		window.setFocusable(true);
		window.setOutsideTouchable(true);
		window.setBackgroundDrawable(new BitmapDrawable());
		window.setAnimationStyle(R.style.AnimationPreview);
	}
	
	
	/**
	 * 设置屏幕变暗
	 */
	public static void changeActivity(Activity con) {
		WindowManager.LayoutParams params = con.getWindow().getAttributes();
		params.alpha = 0.7f;
		con.getWindow().setAttributes(params);

	}

	/**
	 * 回复屏幕
	 */
	public static void changeActivity(PopupWindow pop,final Activity con) {
		pop.setOnDismissListener(new OnDismissListener() {

			@Override
			public void onDismiss() {
				// TODO Auto-generated method stub
				WindowManager.LayoutParams params = con.getWindow().getAttributes();
				params.alpha = 1f;
				con.getWindow().setAttributes(params);
			}
		});

	}

}
